
KernelVersion:=2.6.20.7

KernelSrc:=linux-$(KernelVersion).tar.gz
KernelDir:=linux-$(KernelVersion)

ModuleNam:=e1000
ModuleVer:=7.4.35
ModuleSrc:=$(ModuleNam)-$(ModuleVer).tar.gz
ModuleDir:=$(ModuleNam)-$(ModuleVer)

ModSysDir:=usr/lib/modules/kernel/drivers/net/e1000/ 
ModTarNam:=module.tgz

IptablesL7ForKernel:=kernel-2.6.20-2.6.21-layer7-2.16.1.patch

KerneConfigFile:=default_config

PATCH_KERNEL:=cd $(KernelDir) && patch -p1 < ../$(IptablesL7ForKernel) && cd .. 
PATCH_E1000:=patch -p0 < e1000-$(ModuleVer).patch;

.PHONY: all clean dist_clean

all:bzImage module.tgz

# We must config system head link to myself.
bzImage:$(KernelSrc) default_config
	tar xzf $(KernelSrc)
	rm -rf /usr/src/linux 
	ln `pwd`/$(KernelDir) /usr/src/linux -sf	# Need right of root!
	cp -rf $(KerneConfigFile) $(KernelDir)/.config	
	$(PATCH_KERNEL)
	$(MAKE) -C $(KernelDir) oldconfig
	$(MAKE) -C $(KernelDir)
	cp $(KernelDir)/arch/i386/boot/bzImage ./
	rm -rf /usr/src/linux
	ln -s /usr/src/linux-2.6.20.7 /usr/src/linux

e1000.ko:$(ModuleSrc)
	tar -xzf $(ModuleSrc)
	$(PATCH_E1000)
	$(MAKE) -C $(ModuleDir)/src
	cp $(ModuleDir)/src/e1000.ko ./
	mkdir -p $(ModSysDir)
	cp e1000.ko $(ModSysDir)

module.tgz:default_config
	$(MAKE) -C $(KernelDir) modules_install INSTALL_MOD_PATH=`pwd`/usr
	tar -czf $(ModTarNam) usr 

clean:
	rm -rf bzImage module.tgz e1000.ko
	rm -rf /usr/src/linux
	ln -s /usr/src/linux-2.6.20.7 /usr/src/linux

dist_clean:clean
	rm -rf $(KernelDir) $(KernelSrc) $(ModuleSrc) $(ModuleDir) usr

include ../Makefile.Res
